<?php

namespace model;
use \core\Model;

class ArticleModel extends Model{
   //查询连表后的总行数
    public function all_rows($condition){
      if(empty($condition)) {
          $sql = 'select count(*) as num from bl_article as a join bl_category as c on a.cat_id=c.id';
      }else{
          $sql = 'select count(*) as num from bl_article as a join bl_category as c on a.cat_id=c.id where '.$condition;
      }
        $this->_pdostatement=$this->_pdo->query($sql);
        return $this->_pdostatement->fetch(\PDO::FETCH_ASSOC);
    }



    //连表查询
    public function joinCat($condition=''){
        try {
            if(empty($condition)){
            $sql = "select a.id,a.title,a.cat_id,a.pubtime,a.intro,a.status,a.ad_account,c.name as c_name from  bl_article as a join bl_category as c on a.cat_id=c.id ";
            }else{
                $sql = "select a.id,a.title,a.cat_id,a.pubtime,a.intro,a.status,a.ad_account,c.name as c_name from  bl_article as a join bl_category as c on a.cat_id=c.id where ".$condition;
            }
//        echo ($sql);
//            exit;
            //执行查询语句
            $this->pdostatement =$this->_pdo->query($sql);
        }catch (\PDOException $e){
            $this->outputERR($e);//调用错误输出函数
        }
        return $this->pdostatement->fetchAll();
}
}


//